package com.iss.itemplate.util;

import org.dozer.DozerBeanMapper;
import org.dozer.MappingException;

import java.util.ArrayList;
import java.util.List;

/**
 * **********************************************************************
 * <p/>
 * iServiceSoft Inc © - 2009 All Rights Reserved
 * _____________________________________________
 * <p/>
 * NOTICE:  All information contained herein is, and remains
 * the property of iServiceSoft. Intellectual and technical concepts
 * contained herein are proprietary of iServiceSoft and may be covered
 * by U.S. and Foreign Patents, patents in process, and are protected
 * by trade secret or copyright law.
 * Dissemination of this information or reproduction of this material
 * is strictly forbidden unless prior written permission is obtained
 * from iServiceSoft Incorporated.
 * <p/>
 * ***********************************************************************
 */
public class ITemplateDozerBeanMapper extends DozerBeanMapper {
   @SuppressWarnings("unchecked")
   public <T> List<T> mapCollection(Object source, Class<T> destinationClass, String mapId) throws MappingException {
      List<T> list = new ArrayList<T>();
      if(source instanceof List) {
         List<Object> objects = (List<Object>)source;
         for(Object object : objects) {
            T t = getMappingProcessor().map(object, destinationClass, mapId);
            list.add(t);
         }
      }
      return list;
   }
   
   @SuppressWarnings("unchecked")
   public <T> List<T> mapCollection(Object source, Class<T> destinationClass) throws MappingException {
      List<T> list = new ArrayList<T>();
      if(source instanceof List) {
         List<Object> objects = (List<Object>)source;
         for(Object object : objects) {
            T t = getMappingProcessor().map(object, destinationClass);
            list.add(t);
         }
      }
      return list;
   }
}
